/*
 * TransitSytem Class
 * 
 * Holds Lines and TrainList
 * 
 */
package Track;

import java.util.ArrayList;

/**
 *
 * @author Chris
 */
public class TransitSystem_1 {
    
    //Keeps track of trains on the track 
    protected ArrayList<TrainInfo> TrainList = new ArrayList();
    protected ArrayList<Line> LineList = new ArrayList();
    
    public TransitSystem_1(){
        Line Red = new Line(0);
        Line Green = new Line(1);
        LineList.add(Red);
        LineList.add(Green);
    }
    
    //Add train to TrainList
    protected int addNewTrain(int lineID, int trainID){
        TrainInfo temp;
        if (lineID == 0)
                temp = new TrainInfo(trainID, lineID, 0, 0, -1, -1, 9, 9);
        else temp = new TrainInfo(trainID, lineID, 0, 0, -1, -1, 62, 62);
        
        for (int i = 0; i < TrainList.size(); i++){
            TrainInfo listItem = TrainList.get(i);
            if (listItem.id == trainID)
                return -1;
            
        }
        TrainList.add(temp);
        return temp.id;
        
    
    }
    //Empty index of TrainList
    protected int removeOldTrain(int trainID){
        try{
        TrainList.remove(trainID);
        return trainID;
        }
        catch (IndexOutOfBoundsException e){
            return -1;
        }
    }     
}
